package com.jacen.fzxs.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jacen.fzxs.dao.IBaseDao;
import com.jacen.fzxs.dao.ITopDao;
import com.jacen.fzxs.entity.TopEntity;
import com.jacen.fzxs.service.ITopService;
import com.jacen.fzxs.web.Pager;

@Service
@Transactional(rollbackFor = Exception.class)
public class TopService extends BaseService<TopEntity> implements ITopService {
	
	@Resource
	private ITopDao topDao;
	@Override
	public IBaseDao<TopEntity> getDao() {
		return topDao;
	}
	
	@Override
	public TopEntity getTop() {
		return topDao.getTop();
	}

	@Override
	public void apply(String id) throws Exception {
		topDao.apply(id);
	}

	@Override
	@Transactional(readOnly = true)
	public List<TopEntity> getPage(Pager pager, Map<String, String> params) throws SQLException {
		pager.setTotalCount(getCount(params));
		return topDao.getPage( (pager.getCurPageNum() - 1) * pager.getPageSize(), pager.getPageSize(), params);
	}
	
	@Transactional(readOnly = true)
	public int getCount(Map<String, ? extends Object> params) throws SQLException {
		return topDao.getCount(params);
	}

}
